layui.define([ 'form', 'laydate', 'table','rechargeApi' ], function(exports) {
	var form = layui.form;
	var laydate = layui.laydate;
	var table = layui.table;
	var rechargeApi = layui.rechargeApi;
	var rechargeTable = null;
	
	var view ={
		
		init:function(){
			this.initTable();
			this.initSearchForm();
			this.initToolBar();
			window.dataReload = function(){
				Lib.doSearchForm($("#searchForm"),rechargeTable)
			}
			
			
		},
		initTable:function(){
			rechargeTable = table.render({
				elem : '#rechargeTable',
				height : Lib.getTableHeight(2),
				method : 'post',
				url : Common.ctxPath + '/admin/recharge/list.json' //数据接口
				,page : Lib.tablePage //开启分页
				,limit : 10,
				cols : [ [ //表头
				{
					type : 'checkbox',
					fixed:'left',
				}, {
					field : 'openId',
					title : '用户ID',
					width : 150,
					fixed:'left',
					sort : true
				}, {
					field : 'nickName',
					title : '用户昵称',
					width : 120
				}, {
					field : 'sex',
					title : '性别',
					width : 150
				}, {
					field : 'score',
					title : '透镜分',
					width : 120
				}, {
					field : 'shareId',
					title : '直荐ID',
					width : 120
				}, {
					field : 'pshareId',
					title : '转荐ID',
					width : 120
				}, {
					field : 'createTime',
					title : '创建时间',
					width : 120,
					templet:function(d){
						return Common.getDate(d.createTime);
					},
					sort : true
				}, {
					field : 'lastLogin',
					title : '上次登录时间',
					width : 120,
					templet:function(d){
						return Common.getDate(d.lastLogin);
					},
					sort : true
				}

				] ]

			});
		},
		
		initSearchForm:function(){
			Lib.initSearchForm( $("#searchForm"),rechargeTable,form);
		},
		initToolBar:function(){
			toolbar = {
					edit:function() { //获取选中数目
						var data = Common.getOneFromTable(table,"rechargeTable");
						if(data==null){
							return ;
						}
						var url = "/admin/recharge/edit.do?id="+data.openId;
						Common.openDlg(url,"充值管理>充值");
					},
					exportRecharge:function(){
					    Common.openConfirm("确认要导出这些充值信息?",function(){
					    	rechargeApi.exportRecharge($("#searchForm"),function(fileId){
					           Lib.download(fileId);
					        })
		                })

                    }
				};
			$('.ext-toolbar').on('click', function() {
				var type = $(this).data('type');
				toolbar[type] ? toolbar[type].call(this) : '';
			});
		}
	}

	 exports('index',view);
	
});